<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    var reg = /\.(jpg|jpeg|png|gif)$/

    console.log(reg.exec("a.png"));
    console.log(RegExp.$1);
</script>
</html>